package com.xinqi.modules.prepare.prepare.controller.app;

import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.prepare.prepare.dto.req.PrepareMemberCreateDTO;
import com.xinqi.modules.prepare.prepare.dto.req.PrepareMemberQueryDTO;
import com.xinqi.modules.prepare.prepare.dto.req.PrepareMemberUpdateDTO;
import com.xinqi.modules.prepare.prepare.dto.rsp.PrepareMemberResultDTO;
import com.xinqi.modules.prepare.prepare.service.PrepareMemberService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 备课区成员APP控制层
 *
 * @author: system
 * @date: 2023/03/19
 */
@Tag(name = "prepare-member-App", description = "备课区成员App接口")
@RestController
@RequestMapping("/app/prepare")
@RequiredArgsConstructor
public class PrepareMemberAppController {
    private final PrepareMemberService prepareMemberService;

    /**
     * 备课区成员-分页
     */
    @Operation(summary = "备课区成员-分页")
    @GetMapping("/member/page")
    public R<PageInfo<PrepareMemberResultDTO>> page(@ParameterObject PrepareMemberQueryDTO dto) {
        PageInfo<PrepareMemberResultDTO> page = prepareMemberService.page(dto, dto);
        return R.data(page);
    }

    /**
     * 备课区成员-详情
     */
    @Operation(summary = "备课区成员-详情")
    @GetMapping("/member/{id}")
    public R<PrepareMemberResultDTO> findById(@PathVariable("id") Long id) {
        PrepareMemberResultDTO dto = prepareMemberService.findById(id);
        return R.data(dto);
    }

    /**
     * 新增备课区成员
     */
    @Operation(summary = "新增备课区成员")
    @PostMapping("/member")
    public R<Long> insert(@RequestBody PrepareMemberCreateDTO dto) {
        return R.data(prepareMemberService.insert(dto));
    }

    /**
     * 修改备课区成员
     */
    @Operation(summary = "修改备课区成员")
    @PutMapping("/member/{id}")
    public R<Boolean> update(@PathVariable("id") Long id, @RequestBody PrepareMemberUpdateDTO dto) {
        dto.setId(id);
        return R.data(prepareMemberService.updateById(dto));
    }

    /**
     * 删除备课区成员
     */
    @Operation(summary = "删除备课区成员")
    @DeleteMapping("/member/{id}")
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return R.data(prepareMemberService.deleteById(id));
    }

    /**
     * 批量删除备课区成员
     */
    @Operation(summary = "批量删除备课区成员")
    @DeleteMapping("/{prepare-id}/member/batch")
    public R<Boolean> batchDelete(@Parameter(description = "备课区id", example = "100001") @PathVariable("prepare-id") Long prepareId,
                                  @RequestBody List<Long> ids) {
        return R.data(prepareMemberService.deleteByIds(prepareId, ids));
    }

}
